package com.sinopec.yelofixedreader.stock.inn.presenter

import com.sinopec.basemodule.http.CommonObserver
import com.sinopec.basemodule.http.ExceptionEngine
import com.sinopec.basemodule.model.StockInListModel
import com.sinopec.yelofixedreader.stock.inn.api.StockInApi
import com.sinopec.yelofixedreader.stock.inn.contract.StockInListContract

/**
 * @author lwj
 * @ClassName: StockInListPresenter
 * @Description: 入库列表
 */
class StockInListPresenter(view: StockInListContract.View) :
    StockInListContract.Presenter(view) {

    /**
     * 入库列表
     */
    override fun searchList(machineCode: String) {
        val resultObservable = StockInApi.searchList(machineCode)
        toSubscribe(resultObservable,
            object : CommonObserver<List<StockInListModel>>(mView.context) {
                override fun onNext(list: List<StockInListModel>) {
                    mView.refreshUI(list)
                }

                override fun onError(t: ExceptionEngine.ResponseThrowable) {
                    //mView.refreshUI(getData())
                    mView.showMessage(t.message)
                }
            })
    }

    /**
     * @author lwj
     * @Description:测试数据
     */
    private fun getData(): List<StockInListModel> {
        val list: MutableList<StockInListModel> = ArrayList()
        for (i in 1..9) {
            val model = StockInListModel()
            //任务id
            model.taskRecordId = "1000$i".toLong()
            //任务单号
            model.taskNo = "LJ100203023$i"
            //仓库名称-库位名称
            model.locationName = "镇海AB库" + 1
            //物料名称
            model.mtrlName = "聚丙烯颗粒" + 1
            //预计总重量（吨）
            model.expectedPalletQuantity = "100$i".toBigDecimal()
            //机器码，（移动机器人使用）
            model.machineCode = "00$i"
            //车牌号
            model.taskPriority = "$i".toInt()
            list.add(model)
        }
        return list
    }
}